<template>
	<div>
		<el-row :gutter="24">
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">区域:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="area" placeholder="请选择区域" clearable @change="getCompanyInfo">
					<el-option v-for="item in areaCombo" :label="item.label" :value="item.code"></el-option>
				</el-select>
			</el-col>

			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">品牌:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="brand" placeholder="请选择品牌名称" @change="getCompanyInfo" clearable>
					<el-option v-for="item in brandCombo" :label="item.label" :value="item.code"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">公司:</p>
			</el-col>
			<el-col :span="4" style="text-align: center;">
				<el-select size="small" style="width: 100%;" v-model="companyId" placeholder="请选择公司名称" @change="getactivity" clearable>
					<el-option v-for="item in companyCombo" :label="item.oName" :value="item.id"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">发起部门:</p>
			</el-col>
			<el-col :span="4">
				<el-select v-model="deptId" style="width:100%" placeholder="请选择" left size="small" clearable>
					<el-option v-for="item in deptCombo" :label="item.oName" :value="item.id"></el-option>
				</el-select>
			</el-col>

		</el-row>
		<el-row :gutter="24">
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">活动:</p>
			</el-col>
			<el-col :span="4">
				<el-select v-model="NAMEData" style="width:100%" placeholder="请选择活动" size="small" clearable>
					<el-option v-for="item in nameData" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">状态:</p>
			</el-col>
			<el-col :span="4">
				<el-select v-model="STATUSData" style="width:100%" placeholder="请选择状态" size="small" clearable>
					<el-option v-for="item in statusData" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">有效时间:</p>
			</el-col>
			<el-col :span="4">
				<el-date-picker style="width:95%" v-model="timeData" type="date" :editable=false placeholder="有效时间" size="small">
				</el-date-picker>
			</el-col>

			<el-col :span="2" style="text-align: center;">
				<el-button type="primary" size="small" v-on:click='activityQuery'>查询</el-button>
			</el-col>
			<el-col :span="7" style="text-align: right;margin-left: -30px;">
				<el-button type="primary" size="small" v-on:click='activityAdd' v-if="btnGroup.add">新增</el-button>
				<el-button type="primary" size="small" v-on:click='msgEdit' v-if="btnGroup.edit">编辑</el-button>
				<el-button type="primary" size="small" v-on:click='Export'>导出</el-button>
				<el-button type="primary" size="small" v-on:click='timeAdd' v-if="btnGroup.extend">延长时间</el-button>
			</el-col>

		</el-row>
		<el-row>
			<el-col :span="24">
				<el-table :data="tableData.dataList" stripe border @selection-change="handleSelectionChange2">
					<el-table-column type="selection" width="60" fixed>
					</el-table-column>
					<el-table-column prop="startDepartment" label="发起部门" width="250" :formatter="deptFormate"></el-table-column>

					<el-table-column prop="name" label="活动名称" width="450"></el-table-column>
					<el-table-column prop="gift" label="礼品名称" width="450"></el-table-column>
					<el-table-column prop="couponType" label="优惠券类型" width="120" :formatter="couponCov"></el-table-column>
					<el-table-column prop="couCount" label="单车发券数量" width="130"></el-table-column>
					<el-table-column prop="startDate" align="center" label="开始日期" :editable=false :formatter="timeFormate" width="200"></el-table-column>
					<el-table-column prop="stopDate" align="center" label="终止日期" :editable=false :formatter="timeFormates" width="200"></el-table-column>

					<el-table-column prop="status" label="状态" :formatter="statusCov"></el-table-column>
					<!--<el-table-column label="操作"
						                 width="260"
						                 fixed="right">
							<template scope="scope">
								<el-tooltip class="item"
								            effect="light"
								            content="修改"
								            v-if="btnGroup.edit"
								            placement="top">
									<el-button type="primary"
									           size="mini"
									           class="iconfont icon-dingdan"
									           @click.native.prevent="msgEdit(scope.$index)"></el-button>
								</el-tooltip>

								<el-tooltip effect="light"
								            content="延长时间"
								            placement="top"
								            v-if="scope.row.status=='0' &&btnGroup.extend">
									<el-button type="primary"
									           @click.native.prevent="timeAdd(scope.$index)">延长时间</el-button>
								</el-tooltip>
							</template>
						</el-table-column>-->
				</el-table>
				<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total">
				</el-pagination>
			</el-col>
		</el-row>
		<!--
																																																																																	        	作者：1040117458@qq.com
																																																																																	        	时间：2017-02-2																		        	描述：新增修改界面
																																																																																	        -->
		<el-dialog title="新增活动" v-model="activityFormShow">
			<el-form :model="activityFormData" ref="activityForms" :rules="activityRule" label-width="150px">
				<el-row :gutter="24">
					<el-col :span="24">
						<el-form-item label="活动名称:" prop="name">
							<el-input size="small" placeholder="请输入活动名称" v-model="activityFormData.name">
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="24">
					<el-col :span="24">
						<el-form-item label="赠送礼品:" prop="gift">
							<el-input size="small" placeholder="请输入赠送礼品" v-model="activityFormData.gift">
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="24">
					<el-col :span="12">
						<el-form-item label="发起部门:" prop="startDepartment">
							<el-select v-model="activityFormData.startDepartment" placeholder="请选择发起部门" left size="small">
								<el-option v-for="item in deptCombo" :label="item.oName" :value="item.id">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="优惠券类型:" prop="startDepartment">
							<el-select v-model="activityFormData.couponType" @change="couponTypeChange" placeholder="请选择优惠券类型" size="small">
								<el-option label="优惠券" value="0">
								</el-option>
								<el-option label="储值卡" value="1">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="24">
					<el-col :span="12">
						<el-form-item label="礼品价值:" prop="cost" required>
							<el-input-number size="small" style="width: 95%;" placeholder="请输入礼品价值" :min="0" v-model="activityFormData.cost">
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="activityFormData.couponType == '0'">
						<el-form-item label="材料成本:" prop="degression" required>
							<el-input-number size="small" style="width: 95%;" placeholder="请输入材料成本" :min="0" v-model="activityFormData.degression">
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="activityFormData.couponType == '0'">
						<el-form-item label="工时成本:" prop="gscost" required>
							<el-input-number size="small" style="width: 95%;" placeholder="请输入工时成本" :min="0" v-model="activityFormData.gscost">
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="activityFormData.couponType == '0'">
						<el-form-item label="优惠券数量:" prop="couCount" required>
							<el-input-number size="small" style="width: 95%;" placeholder="请输入工时成本" :min="1" v-model="activityFormData.couCount">
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="开始日期:" prop="startDate">
							<el-date-picker type="date" size="small" style="width: 90%;" placeholder="选择开始日期" v-model="activityFormData.startDate" format="yyyy-MM-dd"></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="结束日期:" prop="stopDate">
							<el-date-picker size="small" style="width: 90%;" v-model="activityFormData.stopDate" format="yyyy-MM-dd" type="date" placeholder="选择结束日期"></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="有效期限（月）:" prop="qixian">
							<el-select prop="qixian" v-model="activityFormData.qixian" placeholder="请选择有效期限" left size="small">
								<el-option v-for="item in qixianData" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="促销类别" prop="cxType">
							<el-select prop="cxType" v-model="activityFormData.cxType" placeholder="请选择促销类别" left size="small">
								<el-option v-for="item in cxTypeCombo" :label="item.label" :value="item.label">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="24">
					<el-col :span="24">
						<el-form-item label="活动规则:" prop="message">
							<el-input size="small" type="textarea" placeholder="请输入活动规则" v-model="activityFormData.message" :autosize="{ minRows: 2, maxRows: 4}" require>
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="activityFormShow = false">取 消</el-button>
				<el-button type="primary" @click="saveActivity">提 交</el-button>
			</div>
		</el-dialog>
		<!--作者：1040117458@qq.com
																																																																																		时间：2017-02-27
																																																																																		描述：延长时间-->
		<el-dialog tittl="延长时间" v-model="timeFormShow">
			<el-form :model="activityFormData" ref="activityForms" :rules="timeRule" label-width="100px">
				<el-col :span="24">
					<el-form-item label="活动名称:" prop="name">
						<el-input size="small" placeholder="请输入内容" v-model="activityFormData.name" readonly>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="结束时间:" prop="stopDate">
						<el-date-picker v-model="activityFormData.stopDate" type="date" placeholder="选择日期"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="有效期限（月）:" prop="qixian">
						<el-select prop="qixian" v-model="activityFormData.qixian" placeholder="请选择" left size="small" clearable>
							<el-option v-for="item in qixianData" :label="item.label" :value="item.value" readonly>
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="timeFormShow = false">取 消</el-button>
				<el-button type="primary" @click="saveTime">提 交</el-button>
			</div>
		</el-dialog>
		<!--
																																																																																		作者：1040117458@qq.com
																																																																																		时间：2017-02-27
																																																																																		描述：车辆分配界面
																																																																																	-->
		<el-dialog tittl="车辆分配" v-model="carFormShow">
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="saveCar">确认分配</el-button>
			</div>
			<el-table :data="carData.dataList" border @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55" label="选择"></el-table-column>
				<el-table-column property="ownerName" label="车主姓名"></el-table-column>
				<el-table-column property="ownerTel" label="车主电话"></el-table-column>
				<el-table-column property="plateNum" label="车牌号"></el-table-column>
				<el-table-column property="brand" label="品牌"></el-table-column>
				<el-table-column property="series" label="车系"></el-table-column>
				<el-table-column property="configure" label="配置"></el-table-column>
				<el-table-column property="modelYear" label="车型年"></el-table-column>
				<el-table-column property="fromCompany" label="是否本公司购买"></el-table-column>
			</el-table>
			<el-pagination small @size-change="handleSizeChange1" @current-change="handleCurrentChange1" :current-page="CurentPage1" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="carData.total">
			</el-pagination>
		</el-dialog>
	</div>
</template>
<script>
	export default {
		data: function() {
			return {
				area: '',
				brand: '',
				companyId: '',
				areaCombo: [],
				brandCombo: [],
				companyCombo: [],
				deptId: "",
				deptCombo: [],
				CurentPage1: 1,
				//分页设置
				CurentPage: 1,
				//每页的数量
				page: this.page,
				//类型转换
				levelConvertData: {},
				//字典转换值
				deptConvert: {},
				//车辆选择存储
				carSelect: [],
				//延长时间表单显示
				timeFormShow: false,
				//车辆分配表单显示
				carFormShow: false,
				//新增修改表单显示
				activityFormShow: false,
				//所选活动查询条件
				NAMEData: '',
				//所选状态查询条件
				STATUSData: '',
				//所选时间查询条件
				timeData: "",

				status: '',

				nameData: {
					total: 0,
					dataList: []
				},
				statusData: {
					total: 0,
					dataList: []
				},
				qixianData: {
					total: 0,
					dataList: []
				},
				// 促销类别
				cxTypeCombo:[],
				tableData: {
					total: 0,
					dataList: []
				},
				//车辆信息
				carData: {
					total: 0,
					dataList: []
				},
				NAME: '',
				//表单初始值
				emptyData: {
					id: '',
					name: '',
					type: '',
					brand: '',
					startDepartment: '',
					startDate: '',
					stopDate: '',
					createDate: '',
					status: ' ',
					message: '',
					gift: '',
					degression: '',
					cost: '',
					qixian: '',
					cxType:'', // 促销类别
					gscost: '',
					couCount: '', //优惠券数量
					couponType: '0', //优惠券类型
					remainder: '', //使用余额
				},
				//表单数据
				activityFormData: {
					id: '',
					name: '',
					type: '',
					brand: '',
					startDepartment: '',
					startDate: '',
					stopDate: '',
					createDate: '',
					status: '',
					message: '',
					gift: '',
					degression: '',
					cost: '',
					qixian: '',
					cxType:'', // 促销类别
					gscost: '',
					couCount: '', //优惠券数量
					couponType: '0', //优惠券类型
					remainder: '', //使用余额
				},
				//车辆表数据初始值
				carEmptyData: {
					ownerName: '',
					ownerTel: '',
					plateNum: '',
					brand: '',
					series: '',
					configure: '',
					modelYear: '',
					fromCompany: '',
				},
				//车主车辆信息表数据
				carFormData: {
					ownerName: '',
					ownerTel: '',
					plateNum: '',
					brand: '',
					series: '',
					configure: '',
					modelYear: '',
					fromCompany: '',
				},
				//表单规则
				activityRule: {
					name: [{
						required: true,
						message: '请输入活动名称',
						trigger: 'blur'
					}],
					gift: [{
						required: true,
						message: '请输入赠送礼品',
						trigger: 'blur'
					}],

					startDate: [{
						type: 'date',
						required: true,
						message: '请选择开始日期',
						trigger: 'blur'
					}],
					stopDate: [{
						type: 'date',
						required: true,
						message: '请选择结束日期',
						trigger: 'blur'
					}],
					qixian: [{
						required: true,
						message: '请选择有效期限',
						trigger: 'change'
					}],
					cxType: [{
						required: true,
						message: '请选择促销类别',
						trigger: 'change'
					}],
					message: [{
						required: true,
						message: '请填写规则说明',
						trigger: 'blur'
					}],

				},
				//延长时间表单规则
				timeRule: {
					name: [{
						required: true,
						message: '请选择活动',
						trigger: 'blur'
					}],
					stopDate: [{
						type: 'date',
						required: true,
						message: '请选择结束时间',
						trigger: 'blur'
					}],
					qixian: [{
						required: true,
						message: '请选择有效期限',
						trigger: 'blur'
					}],
				},
				activity: '',
				btnGroup: {},
				multipleSelection2: [],
			}

		},
		methods: {
			//表格中优惠券类型解析
			couponCov: function(row) {
				if(row.couponType == '1') {
					return "储值卡";
				} else {
					return "优惠券";
				}
			},
			//优惠券类型改变触发方法
			couponTypeChange: function() {
				this.$data.activityFormData.degression = 0;
				this.$data.activityFormData.gscost = 0;
				this.$data.activityFormData.couCount = 1;
			},
			//选择框
			handleSelectionChange2: function(val) {
				debugger;
				this.$data.multipleSelection2 = val;
				if(this.$data.multipleSelection2.length > 1)
					this.$message.error("请选择一条数据！");
			},
			//导出按钮
			Export: function() {
				debugger;
				var dates = this.$data.timeData;
				if(dates == null || dates == "") {
					dates = '';
				} else {
					dates = this.moment(dates).format("YYYY-MM-DD");
				}
				window.location.href = this.API_ROOT + '/crm/activity/excel/export?uid=' + window.localStorage.getItem("uid") + "&&companyId=" + this.$data.companyId +
					"&&id=" + this.$data.NAMEData +
					"&&status=" + this.$data.STATUSData +
					"&&deptId=" + this.$data.deptId +
					"&&time=" + dates +
					"&&brand=" + this.$data.brand +
					"&&area=" + this.$data.area;
			},
			handleSelectionChange: function(val) {
				this.$data.carSelect = val;
			}, //时间选择器
			pickerOptions1: function() {},
			//分配分页切换
			handleSizeChange1: function() {},
			//分配当前页切换
			handleCurrentChange1: function(CurentPage1) {
				this.$data.CurentPage1 = CurentPage1;
				this.carAllotQuery();
			},
			//列表分页大小切换
			handleSizeChange: function() {},
			//列表当前页切换
			handleCurrentChange: function(currentPage) {
				this.$data.CurentPage = currentPage;
				this.resRoleQuery();
			},
			//查询
			resRoleQuery: function() {
				debugger;
				var dates = this.$data.timeData;
				if(dates == null || dates == "") {
					dates = '';
				} else {
					dates = this.moment(dates).format("YYYY-MM-DD");
				}
				if(this.$data.companyId == "") {
					this.$message.error("请选择公司！");
				} else {
					this.$http({
						method: "POST",
						url: this.API_ROOT + '/crm/activity/page', //url
						params: {
							start: this.$data.CurentPage, //页码
							limit: this.$data.page.pageSize, //每页的数量
							id: this.$data.NAMEData,
							status: this.$data.STATUSData,
							deptId: this.$data.deptId,
							time: dates,
							companyId: this.$data.companyId,
							brand: this.$data.brand,
							area: this.$data.area,
						}
					}).then(function(resp) {
						//success
						debugger;
						resp.data.total = parseInt(resp.data.total);
						this.$data.tableData = resp.data;
					}, function(error) {
						//error
					})
				}

			},
			//车辆分配查询
			carAllotQuery: function() {
				this.$http({
					method: "POST",
					url: this.API_ROOT + '/crm/activity/alPage', //url
					params: {
						start: this.$data.CurentPage1, //页码
						limit: this.page.pageSize, //每页的数量
					}
				}).then(function(resp) {
					//success
					resp.data.total = parseInt(resp.data.total);
					this.$data.carData = resp.data;
				}, function(error) {
					//error
				})
			},
			//活动信息保存
			saveActivity: function() {

				this.$refs.activityForms.validate(function(valid) {
					if(valid) {
						var date1 = this.$data.activityFormData.startDate;
						debugger;
						if(date1 == null || date1 == '') {
							this.$data.activityFormData.startDate = '';
						} else {
							//转换成long型
							this.$data.activityFormData.startDate = new Date(date1).getTime();
						};
						var date2 = this.$data.activityFormData.stopDate;
						if(date2 == null || date2 == '') {
							this.$data.activityFormData.stopDate = '';
						} else {
							this.$data.activityFormData.stopDate = new Date(date2).getTime();
						};
						//如果是代金券使用余额 = 礼品价值
						if(this.$data.activityFormData.couponType == 1) {
							this.$data.activityFormData.remainder = this.$data.activityFormData.cost;
						} else {
							this.$data.activityFormData.remainder = '0';
						}
						this.$http.post(this.API_ROOT + '/crm/activity/save', this.$data.activityFormData)
							.then(resp => {
								if(resp.data.success) {
									this.$message(resp.data.msg);
									this.resRoleQuery();
									this.$data.activityFormShow = false;
								} else {
									this.$data.activityFormData.startDate = new Date(this.$data.activityFormData.startDate);

									this.$data.activityFormData.stopDate = new Date(this.$data.activityFormData.stopDate);

									this.$message.error(resp.data.msg);
								}
							}, resp => {

							});
					}
					return false;
				}.bind(this));
			},
			//延长时间保存
			saveTime: function() {
				this.$refs.activityForms.validate(function(valid) {
					if(valid) {
						var dates = this.$data.activityFormData.stopDate;
						if(dates == null || dates == '') {
							this.$data.activityFormData.stopDate = '';
						} else {
							//转换成long型
							this.$data.activityFormData.stopDate = new Date(dates).getTime();
						};
						this.$http.post(this.API_ROOT + '/crm/activity/exTime', null, {

								params: {
									id: this.$data.activityFormData.id,
									stopDate: this.$data.activityFormData.stopDate
								}
							})
							.then(resp => {

								if(resp.data.success) {
									this.$message(resp.data.msg);
									this.resRoleQuery();
									this.$data.timeFormShow = false;
								} else {
									this.$message.error(resp.data.msg);
								}
							}, resp => {

							});
					}
					return false;
				}.bind(this));
			},
			//车辆信息保存
			saveCar: function() {
				debugger;
				this.$http.post(this.API_ROOT + '/crm/activity/alSave', this.$data.carSelect, {
						params: {
							activityId: this.$data.activity.id,
						}
					})
					.then(resp => {
						if(resp.data.success) {
							this.$message(resp.data.msg);
							this.carAllotQuery();
							this.$data.carFormShow = false;
						} else {
							this.$message.error(resp.data.msg);
						}
					}, resp => {

					})
			},
			//修改
			msgEdit: function() {
				debugger;
				if(this.$data.multipleSelection2.length == 1) {

					var resRoleData = this.$data.multipleSelection2[0];
					this.$http({
						method: "GET",
						url: this.API_ROOT + '/crm/activity/info',
						params: {
							id: resRoleData.id,
						}
					}).then((response) => {
						debugger;

						response.data.data.startDate = new Date(Number(response.data.data.startDate));
						response.data.data.stopDate = new Date(Number(response.data.data.stopDate));
						this.$data.activityFormData = Object.assign(this.$data.activityFormData, response.data.data);
						//编辑是判断显示优惠券成本
						if(this.$data.activityFormData.couponType == ''||this.$data.activityFormData.couponType == null||this.$data.activityFormData.couponType == 'null'){
							this.$data.activityFormData.couponType = "0";
						}
					}, (response) => {});
					this.$data.activityFormShow = true;
				} else {
					this.$message.error("请选择一条数据");
				}
			},
			//延长时间
			timeAdd: function() {

				if(this.$data.multipleSelection2.length == 1) {

					var resRoleData = this.$data.multipleSelection2[0];
					if(this.$data.multipleSelection2[0].status == '0') {
						this.$http({
							method: "POST",
							url: this.API_ROOT + '/crm/activity/info',
							params: {
								id: resRoleData.id,
							}
						}).then((response) => {
							response.data.data.stopDate = new Date(Number(response.data.data.stopDate));
							this.$data.activityFormData = Object.assign(this.$data.activityFormData, response.data.data);
							this.$data.timeFormShow = true;
						}, (response) => {});
					} else {
						this.$message.error("此活动未过期，不能延长时间")
					}
				} else {
					this.$message.error("请选择一条数据");
				}
			},
			//停用
			stopResRole: function(index) {
				//
				var data = this.$data.tableData.dataList[index];
				this.$http({
					method: 'POST',
					url: this.API_ROOT + '/crm/activity/stop',
					params: {
						id: data.id,
					}
				}).then(function(resp) {
					if(resp.data.success) {
						this.$message(resp.data.msg);
						//this.resRoleQuery(this.$data.curTreeDeptId);
						//this.$data.groupFormShow = false;
						this.resRoleQuery();
					} else {
						this.$message.error(resp.data.msg);
					}
				}, function(error) {

				})
			},
			//新增
			activityAdd: function() {
				debugger;
				//
				this.$data.activityFormData = Object.assign(this.$data.activityFormData, this.$data.emptyData);
				this.$data.activityFormShow = true;
				//this.$prompt('请选择信息')
			},
			//车辆分配
			carAllot: function(index) {
				this.$data.activity = this.$data.tableData.dataList[index];
				this.$http.post(this.API_ROOT + '/crm/activity/alPage', {
					params: {
						id: this.$data.activity.id,
					}
				}).then(function(resp) {
					if(resp.data.success) {
						//this.$message(resp.data.msg);
						//this.resRoleQuery(this.$data.curTreeDeptId);
						//this.$data.groupFormShow = false;
						this.carAllotQuery();
					} else {
						this.$message.error(resp.data.msg);
					}
				})
				this.$data.carFormShow = true;
			},
			//搜索
			activityQuery: function(val) {
				this.resRoleQuery(val);
			},
			//分组类型解析
			levelCov: function(row, column) {
				return this.$data.levelConvertData[row.type];
			},
			//状态转换
			statusCov: function(row, column) {
				var temp = '';
				switch(row.status) {
					case '0':
						temp = "已停止";
						break;
					case '1':
						temp = '进行中';
						break;
					case "2":
						temp = '未开始';
						break;
					default:
						''
						break
				};
				return temp;
			},
			levelCovert: function() {
				this.$http.get(this.API_ROOT + '/base/dict/convert', {
					params: {
						group: "activityType"
					}
				}).then((response) => {
					this.$data.levelConvertData = response.data;
				}, (response) => {});
			},
			//起始时间解析
			timeFormate: function(row, column) {
				if(row.startDate == "" || row.startDate == null) return "";
				return this.moment(Number(row.startDate)).format("YYYY-MM-DD");
			},
			//结束时间解析
			timeFormates: function(row, column) {
				if(row.stopDate == "" || row.stopDate == null) return "";
				return this.moment(Number(row.stopDate)).format("YYYY-MM-DD");
			},

			deptFormate: function(row, column) {
				if(row.startDepartment == "" || row.startDepartment == null) return "";
				return this.$data.deptConvert[row.startDepartment];
			},
			//获取公司信息
			getCompanyInfo: function() {
				//this.$data.data.companyId = ""; //清空单位
				//				this.$data.companyId = ""; //清空单位
				this.$data.companyCombo = [];
				//
				debugger;
				this.$http.get(this.API_ROOT + "/rbac/dept/all", {
					params: {
						area: this.$data.area,
						brand: this.$data.brand
					}
				}).then(resp => {
					debugger;
					this.$data.companyCombo = resp.data.dataList;
					if(this.$data.companyCombo.length > 0) {
						this.$data.companyId = this.$data.companyCombo[0].id;
					}
				});
			},
			//获取区域
			getarea: function() {

				debugger;
				this.$http.get(this.API_ROOT + "/rbac/dept/area/all", {
					params: {

					}
				}).then(resp => {
					this.$data.areaCombo = resp.data.dataList;
				});
			},
			//获取品牌
			getBrand: function() {
				debugger;
				this.$http.get(this.API_ROOT + "/rbac/dept/brand/all", {
					params: {}
				}).then(resp => {
					this.$data.brandCombo = resp.data.dataList;
				});
			},
			//huoqu bumen
			getDept: function() {
				this.$data.deptId = "";

				debugger;
				this.$http.get(this.API_ROOT + '/rbac/dept/org', {
					params: {
						pId: this.$data.companyId,
					}
				}).then((response) => {
					this.$data.deptCombo = response.data.dataList;
					//					this.getactivity();
					//this.$data.levelConvertData = response.data;
				}, (response) => {});
			},
			//获取活动
			getactivity: function() {
				debugger;
				this.$data.NAMEData = "";
				this.$data.nameData = [];
				//获取所属活动下拉
				this.$http.get(this.API_ROOT + '/crm/activity/combo', {
					params: {
						companyId: this.$data.companyId,
					}
				}).then((response) => {
					debugger;
					this.$data.nameData = response.data;
					this.getDept();
				}, (response) => {});
			},
		},
		//表单创建时执行
		created: function() {
			this.$http({
				method: 'GET',
				url: this.API_ROOT + '/rbac/login/btn', //url 输出 按照车牌号的 车牌号
				params: { //发送的参数
					resPath: "crm/campaign/activity", ////查询条件 按照输入的车牌号
				}
			}).then(function(resp) {
				var btnData = resp.data.dataList;

				var temp = {};

				for(var i = 0; i < btnData.length; i++) {

					var btnName = btnData[i].btnName;

					temp[btnName] = btnName;

				}

				Object.assign(this.$data.btnGroup, temp);
			}, function(error) {
				// error
			})
			//列表查询
			//this.resRoleQuery();
			//分级查询
			this.getarea();
			this.getBrand();
			this.getCompanyInfo();
			//查询类型转换
			this.levelCovert();
			//获取类型下拉
			this.$http.get(this.API_ROOT + '/base/dict/combo', {
				params: {
					group: "030102"
				}
			}).then((response) => {
				this.$data.statusData = response.data;
			}, (response) => {});
			//有效期限（月）
			this.$http.get(this.API_ROOT + '/base/dict/combo', {
				params: {
					group: "activityQixian"
				}
			}).then((response) => {
				this.$data.qixianData = response.data;
			}, (response) => {});

			this.$http.get(this.API_ROOT + '/rbac/dept/convert', {
				params: {}
			}).then((response) => {
				this.$data.deptConvert = response.data;
				//this.$data.levelConvertData = response.data;
			}, (response) => {});
			
			this.$http.get(this.API_ROOT + '/base/dict/combo/insurance', {
				params: {
					group: "0302"
				}
			}).then((response) => {
				this.$data.cxTypeCombo = response.data;
			}, (response) => {});

		}
	}
</script>
<style>
	.el-table .info-row {
		height: 15px !important;
	}

	.item {
		width: 30px;
	}

	.el-dropdown .el-button-group,
	.el-table .el-tooltip,
	.el-table .el-tooltip__rel {
		display: inline;
	}
</style>